package top.xtcoder.jdcbase.base.utils.aesxml;

import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.util.Date;

import org.apache.tomcat.util.codec.binary.Base64;

public class Test {
	/**
	 * PrivateKey: TUlJQ2R3SUJBREFOQmdrcWhraUc5dzBCQVFFRkFBU0NBbUV3Z2dKZEFnRUFBb0dCQUorRjJSY05OSHEzSUJCRU5uaEZxaVNMUkhqQW40NTFlbzh5NFhiZmlqeHQ0Z3NmMGhwdGxKcHBDckJQZWlmRG5iL0Nod0ExQk1ITDB2dTY4ZGMwUmtURVdwQVEwSjNNRXVTeUcwTDF2clFycy9rdUF4Z1g1T0RsWE9jTWFJeTZzMmhYRE0rVEtiTDB3bWZYUmswQWo2ZG9US2lWZjdPUUFnTmRhdmZmbFE3ckFnTUJBQUVDZ1lBQnNQZ1pGcUtWK0h5N3RNQWFiS3Y5OWpJSmU3VlZXOVBWcDlXY2M5M3gxUkpwU1hMcCtudkhCVkpxaGNxRzdidllRc3VPbjRGSGtyaDZiY1FrVFhhL1BldzRwTHYybUtWOVVMNmZrZFVvTFViWkloRDhTaUVLNG9oSVdiYjVRcGFNaFllTVdLbTJnanNxMnY4TEhYMEtMWHJhYUlXaUU5Y3hlTGc1ZVRxNjhRSkJBT0ZMVm9Ia05BR1lSSmsxWFVGKzVkQmNZS0VQQ0VYdVYzcW1YOXhqWUI4Z1ZjQ0VIcjBBNkVLbFpQRGFwck50ODBWRnNoZHF5dlJUL2gwYjI3WUxWcEVDUVFDMVE3UEZtTGZyZTg1ZlNwd0ltVFdLN0J1ZkphdFJnTUZ6M0xSQ29TZGRrRlNSOXRZM1Y3UXVOZWo4N3FYcnp0NGhpc2ZQRDNmZ2lkeERyTzJTaHlPN0FrQkd4bEFLeGhIQVhvRk9VQUZYemZHTUh6a0wzNWtOdnU0a1RaZlh1REErRnY1WldDZi80QVVXeXJhSEkya3kvTnRyYTVXaTNaMmNX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S2V5VmFsdWU+
	 * @param args
	 * @throws InvalidKeySpecException 
	 * @throws NoSuchAlgorithmException 
	 */
	public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException {
		String priKeyStr = "PFJTQUtleVZhbHVlPjxNb2R1bHVzPjJTdkNHbHdRek9IQ3BzZC9kNU1lOEFDelo2TGNVUHBTM0N5a3dJVjhSQXpxZDFrRjFXK3hXZVVvT2xCSms2bGlCZVFvZ1dSTTA0STZxZkJ3MFZSaHAwcWJDNEV2S055SzBtTWZQbGo2T0o2dk1QclpEUENZTGx0SWxlc0F1YkhWaTluWkRJMDhJd2pZaGg1QnhFSzA1NllpSE51emJFaXFFY2VjaFdRUi9UMD08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjxQPjZWSy9IU081WHo4Q3FzR24zSkN4Tit6dENySTA2L09VeEZtV3h5SUVrWEdDczBieUNPdkNKaWZkZHc3Qy9uU1EvZmJwMmRkblNYcWswVTBKY09RQ2J3PT08L1A+PFE+N2tjaGNKSGFzSDB3ekUvbkFiaWRUR3FacElCdmMxcjdBNnFPQW54WDRqSUZFM1FwdHRWSWEwOFU2d2EwcU1MTGhIZVFUWWpNbm1nMHRZYkFVMEtoRXc9PTwvUT48RFA+YVhIOThQdGVJVTltc3lrRjVjWjJjT0hnVnI4bTc2T0xqaGsyN1JQUW9MSjk4T3VWSXJiNWJTa0RDM1ZlWm9UanFnTFd1SjZDalZDaC8vMGkwU1FhZlE9PTwvRFA+PERRPm4yT0hjK1N0RkFmNlg0RkhkcmhHeUhvNlluYmpscGVTZDZaY0xqOTlEanNGZURqcE9uczdZVVRhS2trbkNnaWIyUFdkMnErYXFJL3VTa3RrVlkycGJ3PT08L0RRPjxJbnZlcnNlUT4xYXhFc1MxUEx4V29HSXg0RE5sSktXd2x5ODlvbXN2YWVCeWY3YkRFZkpJbGxnMUZaR3pWbVBFQmxJbCtwQXYweFJPeHFPMTJVVU5EVjZ1UklJVGw0dz09PC9JbnZlcnNlUT48RD55bVg4M2dKRjZoelNCQXZVSVlZdEJETXpBUGlJNnJPUisvOWpnTVluZldpb01KajRWZVpsM01rMHg3eENCbXVMbnIvNGZEY1ZYdDUxZkNKSmt0NVlyeERTMnN2VjJUZFRya3VEcWJMb0pSWnQ4NW5UdW9zRm1OUFpxcklaY1p0Z2srbVpNdTdldFh1MXBqRnUrK3JDZzZXL2Fua3pRa3ozL3RacC9tdFp0ZVU9PC9EPjwvUlNBS2V5VmFsdWU+"; 
		String pubKeyStr = "PFJTQUtleVZhbHVlPjxNb2R1bHVzPjJTdkNHbHdRek9IQ3BzZC9kNU1lOEFDelo2TGNVUHBTM0N5a3dJVjhSQXpxZDFrRjFXK3hXZVVvT2xCSms2bGlCZVFvZ1dSTTA0STZxZkJ3MFZSaHAwcWJDNEV2S055SzBtTWZQbGo2T0o2dk1QclpEUENZTGx0SWxlc0F1YkhWaTluWkRJMDhJd2pZaGg1QnhFSzA1NllpSE51emJFaXFFY2VjaFdRUi9UMD08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjwvUlNBS2V5VmFsdWU+"; 
//		KeyPair kp = RsaHelper.generateRSAKeyPair();
//        PublicKey pubKey = kp.getPublic();
//        PrivateKey priKey = kp.getPrivate();
//
//        String pubKeyXml = RsaHelper.encodePublicKeyToXml(pubKey);
//        String priKeyXml = RsaHelper.encodePrivateKeyToXml(priKey);
//        System.out.println("====公钥====");
//        System.out.println(pubKeyXml);
//        System.out.println("====私钥====");
//        System.out.println(priKeyXml);
//
//        PublicKey pubKey2 = RsaHelper.decodePublicKeyFromXml(pubKeyXml);
//        PrivateKey priKey2 = RsaHelper.decodePrivateKeyFromXml(priKeyXml);
//
//        System.out.println("====公钥对比====");
//        System.out.println(pubKey.toString());
//        System.out.println("------");
//        System.out.println(pubKey2.toString());
//
//        System.out.println("====私钥对比====");
//        System.out.println(priKey.toString());
//        System.out.println("------");
//        System.out.println(priKey2.toString());
//
        try {
            String pubKeyXml3 = new String(Base64.decodeBase64(pubKeyStr));;
            String priKeyXml3 = new String(Base64.decodeBase64(priKeyStr));;

            PublicKey pubKey3 = RsaHelper.decodePublicKeyFromXml(pubKeyXml3);
            PrivateKey priKey3 = RsaHelper.decodePrivateKeyFromXml(priKeyXml3);
            
            String str = "P5Y+ffHDDxBznikCCLWPC8ud4IjtetjWx9V4CzQdARAjjdEoQdQQbdyonPAp8bL7tQnPUaLui6q0oAjZcte6vyLhyT/blSQZTBOokRPZJZciA4OOOWwDX2UywZ6QuGCaTfiKlMm5CE8zQTx7SZSK2ok7NQEbh1an/2uGlDr2G50=";
            byte[] bytes = Base64Helper.decode(str);
                                                                            // byte[]
            byte[] decryptedDataByteArray = RsaHelper.decryptData(bytes, priKey3);
            System.out.println(new String(decryptedDataByteArray, "GB2312"));// 签名

        } catch (Exception ex) {
            ex.printStackTrace();
        }
	}
}
